#include "stdafx.h"
#include "CppUnitTest.h"

#include <HSModel/HeightMap.h>
#include <HSModel/GenerateHeightMap.h>

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace HSModelTests
  {
  TEST_CLASS(GenerateHeightMapTests)
    {
    public:

      TEST_METHOD(ShouldChangeOriginalHeightMap)
        {
        // Arrange
        auto hm = HeightMap(3, 3);
        hm.Set(0, 0, 0);
        hm.Set(0, 2, 4);
        hm.Set(2, 0, 16);
        hm.Set(2, 2, 32);

        // Act
        GeneratedHeightMapWithDiamondSquare(hm, 0.5, 100.0);

        // Assert
        Assert::AreNotEqual(0.0, hm.Get(1, 0));
        Assert::AreNotEqual(0.0, hm.Get(2, 1));
        }

      TEST_METHOD(ShouldGenerateHeightMapWithDiamondSquareAlgorithm)
        {
        // Arrange
        auto hm = HeightMap(5, 5);
        hm.Set(0, 0, 0);
        hm.Set(4, 0, 0);
        hm.Set(0, 4, 0);
        hm.Set(4, 4, 0);

        // Act
        GeneratedHeightMapWithDiamondSquare(hm, 0.6, 100.0);

        // Assert
        Assert::IsTrue(hm.Get(1, 0) >= -40.1);
        Assert::IsTrue(hm.Get(2, 2) <= 40.1);
        Assert::IsTrue(hm.Get(3, 1) >= -40.1);
        Assert::IsTrue(hm.Get(0, 4) <= 40.1);
        }
    };
  }